/*
 * @Description:
 * @Author: xunzhaotech
 * @Email: luyb@xunzhaotech.com
 * @QQ: 1525572900
 * @Date: 2025-03-23 23:04:04
 * @LastEditTime: 2025-03-26 10:21:27
 * @LastEditors: xunzhaotech
 */

import request from '@/config/axios'
// ERP 采购入库 VO`
export interface ProduceOrderVO {
  id: number // 订单工单编号
  no: string // 采购订单号
  customerId: number // 客户编号
  orderTime: Date // 订单时间
  totalCount: number // 合计数量
  totalPrice: number // 合计金额，单位：元
  status: number // 状态
  remark: string // 备注
  outCount: number // 采购出库数量
  returnCount: number // 采购退货数量
}

// ERP 采购订单 API
export const PurchaseOrderApi = {
  purchaseOrderReceive: async (id: number) => {
    return await request.put({
      url: `/erp/purchase-order/confirm-receive`,
      params: {
        id
      }
    })
  },
  purchaseOrderConfirm: async (id: number) => {
    return await request.put({
      url: `/erp/purchase-order/confirm-purchase`,
      params: {
        id
      }
    })
  },
  purchaseOrderCancel: async (id: number) => {
    return await request.put({
      url: `/erp/purchase-order/cancel`,
      params: {
        id
      }
    })
  },
  // 查询采购订单分页
  getPurchaseOrderPage: async (params: any) => {
    return await request.get({ url: `/erp/purchase-order/page`, params })
  },

  // 查询采购订单详情
  getPurchaseOrder: async (id: number) => {
    return await request.get({ url: `/erp/purchase-order/get?id=` + id })
  },

  // 新增采购订单
  createPurchaseOrder: async (data: ProduceOrderVO) => {
    return await request.post({ url: `/erp/purchase-order/create`, data })
  },

  // 修改采购订单
  updatePurchaseOrder: async (data: ProduceOrderVO) => {
    return await request.put({ url: `/erp/purchase-order/update`, data })
  },
  // 确认采购
  confirmPurchase: async (id: number) => {
    return await request.put({
      url: `/erp/purchase-order/confirm-purchase`,
      params: {
        id
      }
    })
  },
  // 取消订单
  updatePurchaseOrderStatus: async (id: number) => {
    return await request.put({
      url: `/erp/purchase-order/cancel`,
      params: {
        id
      }
    })
  },

  // 删除采购订单
  deletePurchaseOrder: async (id: number) => {
    return await request.delete({
      url: `/erp/purchase-order/delete`,
      params: {
        id
      }
    })
  },

  // 导出采购订单 Excel
  exportPurchaseOrder: async (params: any) => {
    return await request.download({ url: `/erp/purchase-order/export-excel`, params })
  }
}

// ERP 生产订单 API
export const ProduceOrderApi = {
  produceOrderCancel: async (id: number) => {
    return await request.put({
      url: `/erp/produce-order/cancel`,
      params: {
        id
      }
    })
  },
  // 查询生产订单分页
  getProduceOrderPage: async (params: any) => {
    return await request.get({ url: `/erp/produce-order/page`, params })
  },

  // 查询生产订单详情
  getProduceOrder: async (id: number) => {
    return await request.get({ url: `/erp/produce-order/get?id=` + id })
  },

  // 新增生产订单
  createProduceOrder: async (data: ProduceOrderVO) => {
    return await request.post({ url: `/erp/produce-order/create`, data })
  },

  // 修改生产订单
  updateProduceOrder: async (data: ProduceOrderVO) => {
    return await request.put({ url: `/erp/produce-order/update`, data })
  },

  // 开始生产
  startProduce: async (id: number) => {
    return await request.put({
      url: `/erp/produce-order/start-produce`,
      params: {
        id
      }
    })
  },

  // 完成生产
  finishProduce: async (id: number) => {
    return await request.put({
      url: `/erp/produce-order/complete-produce`,
      params: {
        id
      }
    })
  },

  // 取消生产订单
  cancelProduceOrder: async (id: number) => {
    return await request.put({
      url: `/erp/produce-order/cancel`,
      params: {
        id
      }
    })
  },

  // 删除生产订单
  deleteProduceOrder: async (id: number) => {
    return await request.delete({
      url: `/erp/produce-order/delete`,
      params: {
        id
      }
    })
  },

  // 导出生产订单 Excel
  exportProduceOrder: async (params: any) => {
    return await request.download({ url: `/erp/produce-order/export-excel`, params })
  }
}
